Visitors and Residents of San Francisco are familiar with the hilly terrain and roads thatclimb into the clouds. But does this topography have an effect on the likelihood of car break-ins? This regression analysis seeks to provide insights into this question.

That is one steep street!
My research question is: "What is the relationship between topography and car break-ins in San Francisco?
This analysis will focus on the link between elevation and “hilliness” in determining the likelihood of car break-ins in San Francisco. Both terrain and motor vehicle crimes are ubiquitous when discussing living or visiting San Francisco. This relationship has been coined by the phrase - “Crime Doesn’t Climb”.
In April 2021, Young-An Kim & James C. Wo published Topography and crime in place: The effects of elevation, slope, and betweenness in San Francisco street segments. Their study provides a robust regression analysis on the effects of elevation, slope, and “hilliness” on crime, controlling for socio-demographic characteristics Kim and Wo (2021). My analysis will focus only on car break-ins rather than all crime reports, as I believe that these crimes will have an even more pronounced relationship with topography.
In order to collect data, we first need to identify our key variables.
Dependent variable: Crime (specifically car break-ins)
Independent variables: Elevation and slope
Control variables: Median income by census block
When discussing topography, both elevation and “hilliness,” or slope, are necessary for inclusion. This is because it more accurately captures the effect of local level topography, which is supported by Kim & Wo.
In any econometric analysis, it is vital to control for socio-economic variables. In this case, it could be that higher elevations in the city are more affluent areas, which may have an impact on crime. Thus, we want to include median income as a control variable.
Here is the regression equation:
\[MotorVehicleTheft_i = \beta_0 + \beta_1Elevation_i + \beta_2Slope_i + \beta_3MedianIncome_i + u_i\]
Crime and elevation data for this analysis were retrieved from the San Francisco Open Data Portal.
Crime - All crime reports from 2018-01-01 to 2021-11-04.
Elevation contours - 5 ft. elevation contours, which were also used to derive slope.
Median income: Retrieved through the tidycensus package via the US Census Bureau.
The analysis plan steps to address this research question are as follows:
Completed in previous sections*
The following code chunk demonstrates how the crime, elevation, slope, and income datasets were merged.
# Find index of nearest contour to each crime
elev <- st_nearest_feature(x = crimes, y = contours)
# Add elevation and binary slope columns
crimes <- crimes %>%
st_join(y = census_geom, join = st_within, left = TRUE) %>%
mutate(elev = contours[elev,]$elevation) %>%
rename(median_income = estimate) %>%
select(date_incid, slope, median_income, elev, geometry)
The following plots show the simple relationships between count of car break ins and the three independent variables (elevation, slope, and median income). We see there is a negative correlation between elevation and crime. It is possible that this relationship is not linear, so this variable may fit better if we take the natural log. Since slope in this analysis is a binary variable, we simply see that there are more crimes in areas that are not designated high slope. Lastly, we observe a weak negative correlation between median income and car break-ins.
# Group by income only
income_summary <- crimes %>%
st_drop_geometry() %>%
group_by(median_income) %>%
summarize(count = n())
income_plot = ggplot(data = income_summary, aes(x = median_income, y = count)) +
geom_point() +
geom_smooth(method = "lm", se = FALSE) +
theme_classic() +
labs(title = "Crime and Median Income",
x = "Median Income (USD)",
y = "Number of Break-Ins")
# Group by elevation
elev_summary <- crimes %>%
st_drop_geometry() %>%
group_by(elev) %>%
summarize(count = n())
elev_plot <- ggplot(data = elev_summary, aes(x = elev, y = count)) +
geom_point() +
geom_smooth(method = "lm", se = FALSE) +
theme_classic() +
labs(title = "Crime and Elevation",
x = "Elevation (feet)",
y = "Number of Break-Ins")
# Group by slope
slope_summary <- crimes %>%
st_drop_geometry() %>%
group_by(slope) %>%
summarize(count = n())
slope_plot <- ggplot(data = slope_summary, aes(x = slope, y = count)) +
geom_point() +
geom_smooth(method = "lm", se = FALSE) +
theme_classic() +
labs(title = "Crime and Slope",
x = "Slope (percent)",
y = "Number of Break-Ins")
elev_plot + (slope_plot / income_plot)

The following plots show crimes over the time period of our data. We can see that there is a slight upward trend to our crime data.
# Group by all three variables
crimes_summary <- crimes %>%
st_drop_geometry() %>%
group_by(slope, median_income, elev) %>%
summarize(count = n())
# Group by date
crimes_ts <- crimes %>%
st_drop_geometry() %>%
group_by(date_incid) %>%
summarize(count = n())
ts_plot <- ggplot(data = crimes_ts, aes(x = date_incid, y = count)) +
geom_point() +
geom_smooth(method = "lm") +
theme_classic() +
labs(title = "Daily Crime 2018-Present",
x = "Date (daily)",
y = "Number of Break-Ins")
crimes_monthly <- crimes_ts %>%
mutate(month = lubridate::floor_date(date_incid, "month")) %>%
group_by(month) %>%
summarize(monthly_sum = sum(count)) %>%
filter(month != "2021-11-01")
monthly_plot <- ggplot(data = crimes_monthly, aes(x = month, y = monthly_sum)) +
geom_point() +
geom_line() +
#geom_smooth(method = "lm") +
theme_classic() +
labs(title = "Monthly Crime 2018-Present",
x = "Date (monthly)",
y = "Number of Break-Ins")
ts_plot + monthly_plot
